﻿#region | Copyright © Siriwat Suananpornpanit 2556 |

/*
	##########################################################################
		Software Generator Code For Hashtable From Table Name => APPTOKEN
		Author By : Siriwat Suananpornpanit
		DateTime : 2556/08/22 11:49:31
	##########################################################################
	*/

#endregion

#region Class | Imports |

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using DataAccess.Interface;
using Microsoft.VisualBasic;
using System.Text;
using DataAccess.DBConnections;
using DataAccess.ProxyConnections;
using Oracle.DataAccess.Client;

#endregion

namespace DataAccess.Dal
{
    internal class ApptokenDal //: IResponsible<Prop.Apptoken>
    {

        /* for DataBase Connection */

        private static DBConnectionsEngine dbEngine;

        private static OracleConnection Conn;

        private static Hashtable hashtable;


        private static ApptokenDal _dal;

        private System.String sql = "";


        public static ApptokenDal GetInstance()
        {
            /* for Init */

            dbEngine = new DBConnectionsEngine();

            Conn = new DatabaseProxy().GetAuthConnection();

            _dal = new ApptokenDal();

            return _dal;
        }

        public IEnumerable<Prop.Apptoken> Select(Prop.Apptoken obj)
        {
            IEnumerable<Prop.Apptoken> entities = new List<Prop.Apptoken>();
            try
            {
                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.DIVISION))
                    {
                        concast.Append(" AND DIVISION=:DIVISION ");
                        hashtable.Add(":DIVISION", obj.DIVISION);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNO))
                    {
                        concast.Append(" AND FUNCNO=:FUNCNO ");
                        hashtable.Add(":FUNCNO", obj.FUNCNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPTOKEN))
                    {
                        concast.Append(" AND APPTOKEN=:APPTOKEN ");
                        hashtable.Add(":APPTOKEN", obj.APPTOKEN);
                    }

                    if (!String.IsNullOrEmpty(obj.TOKEN))
                    {
                        concast.Append(" AND TOKEN=:TOKEN ");
                        hashtable.Add(":TOKEN", obj.TOKEN);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNAME))
                    {
                        concast.Append(" AND APPLNAME=:APPLNAME ");
                        hashtable.Add(":APPLNAME", obj.APPLNAME);
                    }

                    if (!String.IsNullOrEmpty(obj.EMPNO))
                    {
                        concast.Append(" AND EMPNO=:EMPNO ");
                        hashtable.Add(":EMPNO", obj.EMPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.PASSWORD))
                    {
                        concast.Append(" AND PASSWORD=:PASSWORD ");
                        hashtable.Add(":PASSWORD", obj.PASSWORD);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.LANG))
                    {
                        concast.Append(" AND LANG=:LANG ");
                        hashtable.Add(":LANG", obj.LANG);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCTION_GROUP))
                    {
                        concast.Append(" AND FUNCTION_GROUP=:FUNCTION_GROUP ");
                        hashtable.Add(":FUNCTION_GROUP", obj.FUNCTION_GROUP);
                    }

                }
                sql = System.String.Format(@" SELECT DIVISION ,COMPANY_CODE ,FUNCNO ,APPTOKEN ,TOKEN ,APPLNO ,APPLNAME ,EMPNO ,PASSWORD ,CRDATE ,LANG ,FUNCTION_GROUP  FROM APPTOKEN");

                sql = sql + concast.ToString();

                entities = dbEngine.ToList<Prop.Apptoken>(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                entities = null;
            }
            return entities;
        }

        public Boolean Add(Prop.Apptoken obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" INSERT INTO APPTOKEN(DIVISION ,COMPANY_CODE ,FUNCNO ,APPTOKEN ,TOKEN ,APPLNO ,APPLNAME ,EMPNO ,PASSWORD ,CRDATE ,LANG ,FUNCTION_GROUP )
					VALUES(:DIVISION ,:COMPANY_CODE ,:FUNCNO ,:APPTOKEN ,:TOKEN ,:APPLNO ,:APPLNAME ,:EMPNO ,:PASSWORD ,:CRDATE ,:LANG ,:FUNCTION_GROUP ");

                hashtable = new Hashtable();
                hashtable.Add(":DIVISION", obj.DIVISION);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":FUNCNO", obj.FUNCNO);
                hashtable.Add(":APPTOKEN", obj.APPTOKEN);
                hashtable.Add(":TOKEN", obj.TOKEN);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":APPLNAME", obj.APPLNAME);
                hashtable.Add(":EMPNO", obj.EMPNO);
                hashtable.Add(":PASSWORD", obj.PASSWORD);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":LANG", obj.LANG);
                hashtable.Add(":FUNCTION_GROUP", obj.FUNCTION_GROUP);
                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Update(Prop.Apptoken obj)
        {
            Boolean result = false;
            try
            {
                sql = System.String.Format(@" UPDATE APPTOKEN
					SET
					DIVISION=:DIVISION,
					COMPANY_CODE=:COMPANY_CODE,
					FUNCNO=:FUNCNO,
					APPTOKEN=:APPTOKEN,
					TOKEN=:TOKEN,
					APPLNO=:APPLNO,
					APPLNAME=:APPLNAME,
					EMPNO=:EMPNO,
					PASSWORD=:PASSWORD,
					CRDATE=:CRDATE,
					LANG=:LANG,
					FUNCTION_GROUP=:FUNCTION_GROUP");

                hashtable = new Hashtable();
                hashtable.Add(":DIVISION", obj.DIVISION);
                hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                hashtable.Add(":FUNCNO", obj.FUNCNO);
                hashtable.Add(":APPTOKEN", obj.APPTOKEN);
                hashtable.Add(":TOKEN", obj.TOKEN);
                hashtable.Add(":APPLNO", obj.APPLNO);
                hashtable.Add(":APPLNAME", obj.APPLNAME);
                hashtable.Add(":EMPNO", obj.EMPNO);
                hashtable.Add(":PASSWORD", obj.PASSWORD);
                hashtable.Add(":CRDATE", obj.CRDATE);
                hashtable.Add(":LANG", obj.LANG);
                hashtable.Add(":FUNCTION_GROUP", obj.FUNCTION_GROUP);

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

        public Boolean Delete(Prop.Apptoken obj)
        {
            Boolean result = false;
            try
            {

                System.Text.StringBuilder concast = new System.Text.StringBuilder();

                concast.Append(" WHERE 1=1 ");

                hashtable = new Hashtable();

                if (obj != null)
                {
                    if (!String.IsNullOrEmpty(obj.DIVISION))
                    {
                        concast.Append(" AND DIVISION=:DIVISION ");
                        hashtable.Add(":DIVISION", obj.DIVISION);
                    }

                    if (!String.IsNullOrEmpty(obj.COMPANY_CODE))
                    {
                        concast.Append(" AND COMPANY_CODE=:COMPANY_CODE ");
                        hashtable.Add(":COMPANY_CODE", obj.COMPANY_CODE);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCNO))
                    {
                        concast.Append(" AND FUNCNO=:FUNCNO ");
                        hashtable.Add(":FUNCNO", obj.FUNCNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPTOKEN))
                    {
                        concast.Append(" AND APPTOKEN=:APPTOKEN ");
                        hashtable.Add(":APPTOKEN", obj.APPTOKEN);
                    }

                    if (!String.IsNullOrEmpty(obj.TOKEN))
                    {
                        concast.Append(" AND TOKEN=:TOKEN ");
                        hashtable.Add(":TOKEN", obj.TOKEN);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNO))
                    {
                        concast.Append(" AND APPLNO=:APPLNO ");
                        hashtable.Add(":APPLNO", obj.APPLNO);
                    }

                    if (!String.IsNullOrEmpty(obj.APPLNAME))
                    {
                        concast.Append(" AND APPLNAME=:APPLNAME ");
                        hashtable.Add(":APPLNAME", obj.APPLNAME);
                    }

                    if (!String.IsNullOrEmpty(obj.EMPNO))
                    {
                        concast.Append(" AND EMPNO=:EMPNO ");
                        hashtable.Add(":EMPNO", obj.EMPNO);
                    }

                    if (!String.IsNullOrEmpty(obj.PASSWORD))
                    {
                        concast.Append(" AND PASSWORD=:PASSWORD ");
                        hashtable.Add(":PASSWORD", obj.PASSWORD);
                    }

                    if (!Information.IsDate(obj.CRDATE))
                    {
                        concast.Append(" AND CRDATE=:CRDATE ");
                        hashtable.Add(":CRDATE", obj.CRDATE);
                    }

                    if (!String.IsNullOrEmpty(obj.LANG))
                    {
                        concast.Append(" AND LANG=:LANG ");
                        hashtable.Add(":LANG", obj.LANG);
                    }

                    if (!String.IsNullOrEmpty(obj.FUNCTION_GROUP))
                    {
                        concast.Append(" AND FUNCTION_GROUP=:FUNCTION_GROUP ");
                        hashtable.Add(":FUNCTION_GROUP", obj.FUNCTION_GROUP);
                    }

                }
                sql = System.String.Format(@" DELETE FROM APPTOKEN ");

                sql = sql + concast.ToString();

                dbEngine.ExecuteNonQuery(sql, hashtable, Conn);

            }
            catch (System.Exception ex)
            {
                result = true;
            }
            return result;
        }

    }
}

/*
##########################################################################
    Free Software License
##########################################################################
*/
